package com.ruoyi.llm.service;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisMqService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public String BtrOver(String keyId,long totalMillis){
        boolean isOverFlag = false;
        String rBstr = "";
        int count = 0;
        while (!isOverFlag) {
            try {

                // 读取是否执行完成的状态
                rBstr =  redisTemplate.opsForValue().get(keyId);
                // 5分钟还没有返回是否完成的状态，说明机器可能出了错误
                if (StringUtils.isNotBlank(rBstr)) {
                    break;
                }
                if (count * 500 > totalMillis) {
                    break;
                }
                count++;
                // 设置每500毫秒读一次
                Thread.sleep(500);
            } catch (Exception e) {
            }
        }
        return rBstr;
    }

}
